import { DomUtils } from '../utils/DomUtilsMin';


/**
 * 移动端 CSDN 网页美化
 * - 测试网页：https://blog.csdn.net/weixin_43852780/article/details/145923323
 */
export class CSDN {

    static hostname = 'blog.csdn.net';

    main() {
        DomUtils.remove([
            // "前往CSDN APP阅读全文" 弹窗遮罩提示
            '.weixin-shadowbox.wap-shadowbox',
            // "APP内打开" "小程序内打开" 两个按钮
            '.feed-Sign-weixin',
            // 顶部header
            '#csdn-toolbar',
            // 底部评论输入框
            '#operate',
            // 顶部Appbar
            '.aside-header-fixed',
            // 登录弹窗
            '.passport-login-container'
        ]);
        // 文章上外边距
        DomUtils.setCss('#main', { marginTop: 0 });
        // 文章标题上外边距
        DomUtils.setCss('#articleContentId', { marginTop: '20px' });
        DomUtils.setCss('body', { paddingBottom: 0});

        // 展开文章
        document.querySelector('.btn_open_app_prompt_box .read_more_btn')?.click();

        console.log('CSDN1: ', document.body.style.paddingBottom);
        DomUtils.observe(document.body, ['attributes'], { attributeFilter: ['style']}, ({ observer }) => {
            document.body.style.paddingBottom = 0;
            observer.disconnect();
        });
        DomUtils.observe(document.body, ['childList'], { childList: true }, ({ target, observer }) => {
            target.querySelector('.passport-login-container')?.remove();
        });
    }
}